package com.calvin.study.reflect;

import java.lang.reflect.Field;

import com.calvin.study.reflect.model.Cat;

public class ClassDemo1 {

	public static void main(String[] args) {
		try {
			// 获取该类 对应的Class对象
			Class<?> cls = Class.forName("spring.framework.study.reflect.model.Cat");
			System.out.println("类对象 ==> " + cls);
			System.out.println("运行类型 ==> " + cls.getClass());

			System.out.println("包名 ==> " + cls.getPackage().getName());

			System.out.println("类名 ==> " + cls.getName());

			Cat cat = (Cat) cls.newInstance();
			System.out.println(cat);

			Field field = cls.getField("sex");
			System.out.println("获取属性值 ==> " + field.get(cat));

			field.set(cat, 2);
			System.out.println("获取属性值 ==> " + field.get(cat));

			Field[] fields = cls.getFields();
			for (Field f : fields) {
				System.out.println(f.getName());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
